package com.leisurexi.aop.features;

import org.springframework.aop.framework.ProxyFactory;

import java.util.Random;

/**
 * @author: leisurexi
 * @date: 2021-06-03 22:32
 */
public class ThrowAdviceDemo {

    public static void main(String[] args) {
        ThrowAdviceDemo instance = new ThrowAdviceDemo();
        ProxyFactory proxyFactory = new ProxyFactory(instance);
        proxyFactory.addAdvice(new MyThrowsAdvice());
        ThrowAdviceDemo proxy = (ThrowAdviceDemo) proxyFactory.getProxy();
        proxy.execute();
        proxy.execute();
    }

    public void execute() {
        Random random = new Random();
        if (random.nextBoolean()) {
            throw new RuntimeException("For Purpose.");
        }
        System.out.println("Executing...");
    }

}
